<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The RegexIterator class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="recursivetreeiterator.valid.html">« RecursiveTreeIterator::valid</a></li>
      <li style="float: right;"><a href="regexiterator.accept.html">RegexIterator::accept »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="spl.iterators.html">迭代器</a></li>
    <li>The RegexIterator class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.regexiterator" class="reference">
 <h1 class="title">The RegexIterator class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p>


  <div class="section" id="regexiterator.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    This iterator can be used to filter another iterator based on a regular expression.
   </p>
  </div>


  <div class="section" id="regexiterator.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">RegexIterator</strong>
     </span>

     <span class="ooclass">
      <span class="modifier">extends</span>
       <a href="class.filteriterator.html" class="classname">FilterIterator</a>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 常量 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.regexiterator.html#regexiterator.constants.use-key"><var class="varname">USE_KEY</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.regexiterator.html#regexiterator.constants.invert-match"><var class="varname">INVERT_MATCH</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.regexiterator.html#regexiterator.constants.match"><var class="varname">MATCH</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.regexiterator.html#regexiterator.constants.get-match"><var class="varname">GET_MATCH</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.regexiterator.html#regexiterator.constants.all-matches"><var class="varname">ALL_MATCHES</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.regexiterator.html#regexiterator.constants.split"><var class="varname">SPLIT</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.regexiterator.html#regexiterator.constants.replace"><var class="varname">REPLACE</var></a></var>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span>
      <var class="varname"><a href="class.regexiterator.html#regexiterator.props.replacement">$<var class="varname">replacement</var></a></var><span class="initializer"> = null</span>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="regexiterator.construct.html" class="methodname">__construct</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.iterator.html" class="type Iterator">Iterator</a></span> <code class="parameter">$iterator</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = RegexIterator::MATCH</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$pregFlags</code><span class="initializer"> = 0</span></span><br>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.accept.html" class="methodname">accept</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.getflags.html" class="methodname">getFlags</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.getmode.html" class="methodname">getMode</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.getpregflags.html" class="methodname">getPregFlags</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.getregex.html" class="methodname">getRegex</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.setflags.html" class="methodname">setFlags</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.setmode.html" class="methodname">setMode</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="regexiterator.setpregflags.html" class="methodname">setPregFlags</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$pregFlags</code></span>): <span class="type"><span class="type void">void</span></span></div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 继承的方法 */</div>
    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="filteriterator.accept.html" class="methodname">FilterIterator::accept</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="filteriterator.current.html" class="methodname">FilterIterator::current</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="filteriterator.getinneriterator.html" class="methodname">FilterIterator::getInnerIterator</a></span>(): <span class="type"><a href="class.iterator.html" class="type Iterator">Iterator</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="filteriterator.key.html" class="methodname">FilterIterator::key</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="filteriterator.next.html" class="methodname">FilterIterator::next</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="filteriterator.rewind.html" class="methodname">FilterIterator::rewind</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="filteriterator.valid.html" class="methodname">FilterIterator::valid</a></span>(): <span class="type">bool</span></div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="iteratoriterator.current.html" class="methodname">IteratorIterator::current</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="iteratoriterator.getinneriterator.html" class="methodname">IteratorIterator::getInnerIterator</a></span>(): <span class="type"><span class="type">?</span><span class="type"><a href="class.iterator.html" class="type Iterator">Iterator</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="iteratoriterator.key.html" class="methodname">IteratorIterator::key</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="iteratoriterator.next.html" class="methodname">IteratorIterator::next</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="iteratoriterator.rewind.html" class="methodname">IteratorIterator::rewind</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="iteratoriterator.valid.html" class="methodname">IteratorIterator::valid</a></span>(): <span class="type">bool</span></div>

   }</div>

  </div>

  <div class="section" id="regexiterator.constants">
   <h2 class="title">预定义常量</h2>
   <div class="section" id="regexiterator.constants.operation-modes">
    <h2 class="title">RegexIterator operation modes</h2>
    <dl>

     
      <dt id="regexiterator.constants.all-matches"><strong><code>RegexIterator::ALL_MATCHES</code></strong></dt>

      <dd>

       <p class="para">
        Return all matches for the current entry 
        (see <span class="function"><a href="function.preg-match-all.html" class="function">preg_match_all()</a></span>).
       </p>
      </dd>

     

     
      <dt id="regexiterator.constants.get-match"><strong><code>RegexIterator::GET_MATCH</code></strong></dt>

      <dd>

       <p class="para">
        Return the first match for the current entry 
        (see <span class="function"><a href="function.preg-match.html" class="function">preg_match()</a></span>).
       </p>
      </dd>

     

     
      <dt id="regexiterator.constants.match"><strong><code>RegexIterator::MATCH</code></strong></dt>

      <dd>

       <p class="para">
        Only execute match (filter) for the current entry 
        (see <span class="function"><a href="function.preg-match.html" class="function">preg_match()</a></span>).
       </p>
      </dd>

     

     
      <dt id="regexiterator.constants.replace"><strong><code>RegexIterator::REPLACE</code></strong></dt>

      <dd>

       <p class="para">
        Replace the current entry 
        (see <span class="function"><a href="function.preg-replace.html" class="function">preg_replace()</a></span>; Not fully implemented yet)
       </p>
      </dd>

     

     
      <dt id="regexiterator.constants.split"><strong><code>RegexIterator::SPLIT</code></strong></dt>

      <dd>

       <p class="para">
        Returns the split values for the current entry (see <span class="function"><a href="function.preg-split.html" class="function">preg_split()</a></span>).
       </p>
      </dd>

     
    </dl>

   </div>
   <div class="section" id="regexiterator.constants.flags">
    <h2 class="title">RegexIterator Flags</h2>
    <dl>
     
      <dt id="regexiterator.constants.use-key"><strong><code>RegexIterator::USE_KEY</code></strong></dt>

      <dd>

       <p class="para">
        Special flag: Match the entry key instead of the entry value.
       </p>
      </dd>

     

     
      <dt id="regexiterator.constants.invert-match"><strong><code>RegexIterator::INVERT_MATCH</code></strong></dt>

      <dd>

       <p class="para">
        Inverts the return value of <span class="methodname"><a href="regexiterator.accept.html" class="methodname">RegexIterator::accept()</a></span>.
       </p>
      </dd>

     

    </dl>

   </div>
  </div>

  <div class="section" id="regexiterator.props">
   <h2 class="title">属性</h2>
   <dl>
    
     <dt id="regexiterator.props.replacement">
      <var class="varname">replacement</var>
     </dt>

     <dd>

      <p class="para"/>
     </dd>

    
   </dl>

  </div>



 </div>

 

































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="regexiterator.accept.html">RegexIterator::accept</a> — Get accept status</li><li><a href="regexiterator.construct.html">RegexIterator::__construct</a> — Create a new RegexIterator</li><li><a href="regexiterator.getflags.html">RegexIterator::getFlags</a> — Get flags</li><li><a href="regexiterator.getmode.html">RegexIterator::getMode</a> — Returns operation mode</li><li><a href="regexiterator.getpregflags.html">RegexIterator::getPregFlags</a> — Returns the regular expression flags</li><li><a href="regexiterator.getregex.html">RegexIterator::getRegex</a> — Returns current regular expression</li><li><a href="regexiterator.setflags.html">RegexIterator::setFlags</a> — Sets the flags</li><li><a href="regexiterator.setmode.html">RegexIterator::setMode</a> — Sets the operation mode</li><li><a href="regexiterator.setpregflags.html">RegexIterator::setPregFlags</a> — Sets the regular expression flags</li></ul>
</div>
</div></div></body></html>